package com.taxigang.client.uibinder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Session;
import com.taxigang.client.TaxiGangHandler;
import com.taxigang.client.facebook.ConnectState;
import com.taxigang.client.facebook.FacebookApi;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.ui.map.MapView.PanelType;

public class Sorry extends TaxiGangPanel  {

	private static SorryUiBinder uiBinder = GWT.create(SorryUiBinder.class);

	interface SorryUiBinder extends UiBinder<Widget, Sorry> {
	}

	@UiField Button yesButton;
	@UiField Button noButton;
	@UiField Label sorryText;
	@UiField
	Label headerLabel;

	public Sorry() {
		initWidget(uiBinder.createAndBindUi(this));
		sorryText.setText(TaxiGangCreator.taxiGangConstants.noTaxiGangsFound());
		yesButton.setText(TaxiGangCreator.taxiGangConstants.yesPlease());
		noButton.setText(TaxiGangCreator.taxiGangConstants.noThanks());
		headerLabel.setText(TaxiGangCreator.taxiGangConstants.sorry());

		yesButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				
				  AsyncCallback<ConnectState> callback =  new AsyncCallback<ConnectState>() {

						@Override
						public void onFailure(Throwable caught) {
							Window.alert("error"+caught.getMessage());
						}

						@Override
						public void onSuccess(ConnectState result) {
							TaxiGangHandler.getInstance().createWishRoute();
							taxiGangRoute.show(PanelType.SEARCH);
						}
					};

				FacebookApi.getEmail(callback);
			}
		});

		noButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				taxiGangRoute.show(PanelType.SEARCH);
			}
		});

	}

}
